﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace smp.ButterflyCakes.Models.FormModels.Order
{
    public class ComponentSizeModel : IOrderModel
    {
        public ComponentSizeModel()
        {
            Sizes = new List<ComponentSizeModelItem>();
        }

        [Required]
        public Guid OrderId { get; set; }

        [Required]
        public Guid ComponentId { get; set; }

        public int TotalPortions { get; set; }

        public bool IsCarved { get; set; }

        public List<ComponentSizeModelItem> Sizes { get; set; }

        public SelectItem SelectShape {get { return new SelectItem("Shape", typeof (CakeShape), null, true); }}

        public void AddSizes(List<ComponentSizeModelItem> sizes)
        {
            foreach(var item in sizes)
            {
                item.IsCarved = IsCarved;
                Sizes.Add(item);
            }
        }
    }

    public class ComponentSizeModelItem
    {
        public Guid SizeId { get; set; }

        public string DisplayName
        {
            get
            {
                var isCustomText = "";
                if(IsCarved)
                {
                    isCustomText = "Custom ";
                }
                switch (Shape)
                {
                    case CakeShape.Round:
                        return isCustomText + "Round : " + Size + " inches diameter";
                    case CakeShape.Square:
                        return isCustomText + "Squary : " + Size + " inches across";
                    case CakeShape.Rectangle:
                        return isCustomText + "Rectangle : " + Size + " inches by " + Width + " inches";
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }
        }

        public bool IsCarved { get; set; }

        public int Size { get; set; }

        public int Width { get; set; }

        public CakeShape Shape { get; set; }

        public int ShapeInt { get { return (int) Shape; } }

        public int Portions { get; set; }

        public string CustomDetail { get; set; }
    }
}
